define(['jquery', 'table', 'form'], function ($, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/index',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
                        {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime},
                        {field: 'temple_name', title: __('Bind temple name'), searchable:false},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                text: __('Note list'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-topic-list btn-dialog',
                                url:'user/note_list'
                            },{
                                name: 'detail',
                                text: __('Bind temple'),
                                icon: 'fa fa-tower',
                                classname: 'btn btn-info btn-xs btn-detail  btn-dialog',
                                url:'user/bind_temple'
                            }],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        note_list: function () {
            console.info('aaa');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/note_list/ids/'+Config.user_id
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'name', title: __('Note name')},
                        {field: 'temple_name', title: __('Temple name'),operate:false,searchable:false},
                        {field: 'desc', title: __('Desc')},
                        {field: 'content_text', title: __('Content'), operate:false, formatter: Table.api.formatter.label},
                        {field: 'solve_note_text', title: __('Solve note'), operate:false, formatter: Table.api.formatter.label}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        bind_temple:function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});